<!--头部公共部分-->
{include file="common/header" /}
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>新增课程</cite></a>
      </span>
    <a class="layui-btn layui-btn-xs layui-btn-small" style="margin-top:7px;float:right;margin-left: 10px;"
       href="{:url('course/course_manage')}">
        返回课程管理</a>

</div>
<div style="padding:15px;">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">基本信息</li>
            <li>课程授权</li>
            <li>上课进度</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form" action="" method="POST">
                    <input type="hidden" name="course_type" value="{$data[9][0]['id']}">
                    <input type="hidden"  value="{$data[9][0]['name']}">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>课程所属</label>
                            <div class="layui-input-inline">
                                <select name="course_ascription" lay-verify="required" lay-search="">
                                    <option value="">请选择</option>
                                    {volist name="data[11]" id="v"}
                                    <option value="{$v.id}">{$v['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>课程年份</label>
                            <div class="layui-input-inline">
                                <select name="course_year" lay-verify="required" lay-search="">
                                    <option value="">请选择</option>
                                    {volist name="data[12]" id="v"}
                                    <option value="{$v.id}">{$v['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">课程季度</label>
                            <div class="layui-input-inline">
                                <select name="course_quarter" lay-search="">
                                    <option value="">请选择</option>
                                    {volist name="data[13]" id="v"}
                                    <option value="{$v.id}">{$v['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>适用年级</label>
                            <div class="layui-input-inline">
                                <select name="student_grade" lay-verify="required" lay-search="">
                                    <option value="">请选择</option>
                                    {volist name="data[1]" id="v"}
                                    <option value="{$v.id}">{$v['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">课程分类</label>
                            <div class="layui-input-inline">
                                <select name="course_cate" lay-search="">
                                    <option value="">请选择</option>
                                    <option value="1">常规1对1</option>
                                    <option value="2">精品1对1</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">费用分类</label>
                            <div class="layui-input-inline">
                                <select name="cost_type" lay-search="">
                                    <option value="">请选择</option>
                                    {volist name="data[14]" id="v"}
                                    <option value="{$v.id}">{$v['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">优惠设置</label>
                            <div class="layui-input-inline">
                                <select name="preferential_setting" lay-search="">
                                    <option value="">请选择</option>
                                    {volist name="data[15]" id="v"}
                                    <option value="{$v.id}">{$v['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>适用校区</label>
                            <div class="layui-inline">
                                {volist name="data[5]" id="v"}
                                <input type="checkbox" name="campus[]" value="{$v['id']}" lay-skin="primary" checked title="{$v['name']}"> &emsp;
                                {/volist}
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>限时课消</label>
                            <div class="layui-inline">
                                <input type="radio" lay-filter="class_elimination" name="class_elimination"  class="layui-input" value="0" title="不限" checked >
                                <input type="radio" lay-filter="class_elimination" name="class_elimination"  class="layui-input" value="1" title="限到期日期">
                                <input type="radio" lay-filter="class_elimination" name="class_elimination"  class="layui-input" value="2" title="限使用天数">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline date">
                            <label class="layui-form-label"><span style="color: red;">*</span>到期日期</label>
                            <div class="layui-input-inline">
                                <input type="text" name="expiration_date" id="start_one"  placeholder="到期日期" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline today">
                            <label class="layui-form-label"><span style="color: red;">*</span>使用天数</label>
                            <div class="layui-input-inline">
                                <input type="text" name="days" placeholder="使用天数" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>适用科目</label>
                        <div class="layui-input-block">
                            {volist name="data[10]" id="v"}
                                <input type="checkbox" name="subjects[]" value="{$v['id']}" lay-skin="primary" checked title="{$v['name']}"> &emsp;
                            {/volist}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input class="layui-btn" lay-submit lay-filter="wxsubmit" id="sub" value="立即提交" readonly>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--底部公共部分-->
{include file="common/footer" /}


<script>
    layui.use(['element','jquery','form','layer','laydate'], function(){
        var $ = layui.jquery,
            element = layui.element,
            laydate = layui.laydate,
            layer = layui.layer,
            form = layui.form;



        $(".date").hide();
        $(".today").hide();
        form.on('radio(class_elimination)', function(data){
            if(data.value === '0') {
                $(".date").hide();
                $(".today").hide();
            }else if(data.value === '1') {
                $(".date").show();
                $(".today").hide();
            }else if(data.value === '2'){
                $(".date").hide();
                $(".today").show();
            }
            form.render('radio');
        });

        //日期
        laydate.render({
            elem: '#start_one',
            type: 'date'
            ,trigger: 'click'
        });

        form.on('submit(wxsubmit)', function (data) {
            var field = data.field;
            $.ajax({
                type: 'post',
                url: '{:url("course/add_course")}',
                data: field,
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 0) {
                        setTimeout(function () {
                            location.href = '{:url("course/course_manage")}';
                        }, 2000);
                    }
                }
            });
        });

        form.on('submit(alisubmit)', function (data) {
            var field = data.field;
            $.ajax({
                type: 'post',
                url: '{:url("course/add_course")}',
                data: field,
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 0) {
                        setTimeout(function () {
                            location.href = '{:url("course/course_manage")}';
                        }, 2000);
                    }
                }
            });
        });
    });
</script>
